package com.cmccgz.udacs_landlord_webapp.main.housemanager.manager;

import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.cmccgz.baselibrary.base.BaseFragment;
import com.cmccgz.udacs_landlord_webapp.R;
import com.cmccgz.udacs_landlord_webapp.adapter.HouseManagerAdapter;
import com.cmccgz.udacs_landlord_webapp.bean.HouseManagerBean;
import com.cmccgz.udacs_landlord_webapp.utils.ViewHelper;

import java.util.List;

/**
 * @author: Huang
 * @Descripion:
 * @date 2017/6/5 10:31
 */

public class HouseManagerFragment extends BaseFragment implements HouseManagerContract.View,View.OnClickListener {

    private HouseManagerContract.Presenter mPresenter;
    private HouseManagerAdapter adapter;
    private RecyclerView rv_list;

    public static HouseManagerFragment newInstance(){
        return new HouseManagerFragment();
    }

    @Override
    protected int setLayoutId() {
        return R.layout.fragment_housemanager;
    }

    @Override
    protected void initView() {
        ViewHelper mViewHelper = ViewHelper.instance(this);
        if (mViewHelper !=null) {
            mViewHelper.setTitle("房屋管理");
            mViewHelper.setAllVisable(false);
            mViewHelper.setBackTextVisable(true);
        }
        rv_list = (RecyclerView) findViewById(R.id.rv_list);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        rv_list.setLayoutManager(layoutManager);
        adapter = new HouseManagerAdapter(mContext);
        rv_list.setAdapter(adapter);
        rv_list.addItemDecoration(new DividerItemDecoration(mContext,DividerItemDecoration.VERTICAL));
        mPresenter.initData();
    }

    @Override
    public void setData(List<HouseManagerBean> beanList) {
        if (adapter==null){
            adapter = new HouseManagerAdapter(mContext);
            rv_list.setAdapter(adapter);
        }
        if (beanList!=null){
            adapter.notifyData(beanList);
        }
    }

    @Override
    public void setPresenter(HouseManagerContract.Presenter presenter) {
        this.mPresenter = presenter;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_back:
                mContext.finish();
                break;
        }
    }
}
